package com.finance.cooperate.feature.reader;

import com.finance.cooperate.common.constant.Constant;
import com.finance.cooperate.feature.base.ReaderImpl;
import com.finance.cooperate.feature.core.feature.FeatureDefinition;
import com.finance.cooperate.feature.core.feature.FeatureOneHotType;
import com.finance.cooperate.feature.dto.DeviceDTO;

import java.util.Map;

/**
 * @ClassName DeviceReader
 * @Description 设备信息抽取
 * @Author shen
 * @Date 2022/5/26 22:44
 * @Modify ...
 */
public class DeviceReader extends ReaderImpl {

    @Override
    public Map<String, String> read(String userId) {

        DeviceDTO info = deviceService.getInfo(userId);

        Long brandCode = featureOneHotService.getOneHotCode(FeatureOneHotType.ONE_HOT_FEATURE_TYPE_001.getValue(), info.getDeviceBrand());
        if (brandCode != null) {
            super.put(FeatureDefinition.f_device_brand_.getValue() + brandCode, Constant.IS_HIT);
        }

        Long operatorCode = featureOneHotService.getOneHotCode(FeatureOneHotType.ONE_HOT_FEATURE_TYPE_002.getValue(), info.getOperator());
        if (operatorCode != null) {
            super.put(FeatureDefinition.f_device_operator_.getValue() + operatorCode, Constant.IS_HIT);
        }

        Long timeZoneCode = featureOneHotService.getOneHotCode(FeatureOneHotType.ONE_HOT_FEATURE_TYPE_003.getValue(), info.getTimeZone());
        if (timeZoneCode != null) {
            super.put(FeatureDefinition.f_device_time_zone_.getValue() + timeZoneCode, Constant.IS_HIT);
        }

        Long countryCode = featureOneHotService.getOneHotCode(FeatureOneHotType.ONE_HOT_FEATURE_TYPE_004.getValue(), info.getCountry());
        if (countryCode != null) {
            super.put(FeatureDefinition.f_device_country_.getValue() + countryCode, Constant.IS_HIT);
        }

        Long networkCode = featureOneHotService.getOneHotCode(FeatureOneHotType.ONE_HOT_FEATURE_TYPE_005.getValue(), info.getNetworkType());
        if (networkCode != null) {
            super.put(FeatureDefinition.f_device_network_.getValue() + networkCode, Constant.IS_HIT);
        }

        super.put(FeatureDefinition.f_device_mac_address_is_blank, info.getMacAddressIsBlank());
        super.put(FeatureDefinition.f_device_cpu_num, info.getCpuNum());
        super.put(FeatureDefinition.f_device_resolution_total, info.getResolutionTotal());
        super.put(FeatureDefinition.f_device_total_storage_size, info.getTotalStorageSize());
        super.put(FeatureDefinition.f_device_can_use_storage_size, info.getCanUseStorageSize());
        super.put(FeatureDefinition.f_device_total_memory_size, info.getTotalMemorySize());
        super.put(FeatureDefinition.f_device_sd_total_size, info.getSdTotalSize());
        super.put(FeatureDefinition.f_device_sd_can_use_size, info.getSdCanUseSize());


        Integer uidCount = deviceService.getSameDeviceUidCount(userId);
        super.put(FeatureDefinition.f_device_same_user_count, uidCount);

        return super.getResult();
    }

}
